package org.chen.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.chen.mapper.ArticleRepository;
import org.chen.domain.CrawlerTask;
import org.chen.processor.FreeSuperTipsPageProcessor;
import org.chen.service.base.BaseWebMagicCrawlerService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import us.codecraft.webmagic.processor.PageProcessor;

@Slf4j
@Service
public class FreeSuperTipsCrawlerServiceImpl extends BaseWebMagicCrawlerService {

    @Value("${crawler.sites.freesupertips.url}")
    private String siteUrl;

    @Value("${crawler.sites.freesupertips.enabled}")
    private boolean enabled;

    public FreeSuperTipsCrawlerServiceImpl(ArticleRepository articleRepository) {
        super(articleRepository);
    }

    @Override
    protected PageProcessor getPageProcessor(CrawlerTask task) {
        task.setStartUrl(siteUrl);
        return new FreeSuperTipsPageProcessor(task);
    }

    @Override
    public String getSourceName() {
        return "freesupertips";
    }

    @Override
    public boolean isSourceAvailable() {
        return enabled;
    }

}